package com.example.sls.mapper.teacher;

import com.example.sls.pojo.Class._Class;
import com.example.sls.pojo.teacher.Teacher;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository

public interface TeacherMapper {

    @Select("select * from teacher")
    @Results(id ="teacherMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "teacherId", property = "teacherId"),
            @Result(column = "name", property = "name"),
            @Result(column = "teacherId", property = "classes", many =
            @Many(select = "com.example.sls.mapper.Class.ClassMapper.getClassesByTId", fetchType = FetchType.DEFAULT))
    })
    List<Teacher> getTeacherInfo();

//    @Select("select * from class where tid = #{tid}; ")
//    List<_Class>getClasses(@Param("tid")Integer tid);

    @Select("select * from teacher where id = #{id}")
    @ResultMap("teacherMap")
    Teacher getTeacherById(@Param("id") Integer id);

    @Select("select * from teacher where teacherId = #{tid}")
    @ResultMap("teacherMap")
    Teacher getTeacherByTId(@Param("tid") Integer tid);

    @Insert("insert into teacher values(#{id},#{teacherId},#{name});")
    Integer addTeacher(Teacher teacher);

    @Select("select max(id) from teacher;")
    Integer getMaxId();

    @Select("select count(*) from teacher;")
    Integer getCount();

}
